package com.songshuai.webapi.jobapi.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum LessonStateEnum {
    No(0, "未上"),
    Yes(1,"已上"),
    Confirm(2, "待确认");
    private int code;
    private String msg;

    LessonStateEnum(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return LessonStateEnum.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public  static  int getCodeByMsg(String msg)
    {
        Integer response=0;
        try{
            for (LessonStateEnum item : LessonStateEnum.values())
            {
                if(item.getMsg().equals(msg))
                {
                    response= item.getCode();
                    break;
                }
            }
        }
        catch (IllegalArgumentException e)
        {
            log.error("undefined error code: {}", msg);
            return 0;
        }
        return response;
    }

    public static String getMsg(String define){
        try {
            return LessonStateEnum.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(LessonStateEnum err : LessonStateEnum.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
